//
//  ExamineDetailsModel.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/8/26.
//

#import "ExamineDetailsModel.h"

@implementation ExamineDetailsModel
+ (NSDictionary *)modelCustomPropertyMapper {
    return @{@"ID":@[@"id"],
    };
}

+ (NSDictionary *)modelContainerPropertyGenericClass {
    return @{
        @"handoverProcessModel":[handoverProcessModel class],
        @"pondTissues":[CombinedPunchTissueListModel class],
    };
}

- (NSString *)tissueListStr{
    if(!_tissueListStr){
        NSMutableArray <NSString *>* strArray = [NSMutableArray array];
        for (CombinedPunchTissueListModel * model in self.pondTissues) {
            NSString * str = [NSString stringWithFormat:@"%@ (%@)",model.pondTissue,model.pondName];
            [strArray addObject:str];
        }
        _tissueListStr = [strArray componentsJoinedByString:@"\n"];
    }
    return _tissueListStr;
}

- (CGFloat)tissueListStrH{
    CGFloat textH = [DTKTool textWithtitle:self.tissueListStr andSize:CGSizeMake(kwt(315), 10000) andFout:kCFont(16)].height;
    if(textH < kwt(15)){
        return kwt(15);
    }
    return textH;
}
- (NSString *)stateStr{
    ///处理状态 1 待审核 2 已同意 3 已拒绝 4 已撤销
    if(self.status == 1){
        return @"待审核 ";

    } else if (self.status == 2){
        return @"已同意";

    } else if (self.status == 3){
        return @"已拒绝";

    } else if (self.status == 4){
        return @"已撤销";

    } else {
        return @"";
    }
}
- (CGFloat)JJcellH{
    CGFloat H = 0;
    if(self.time.length > 0){
        H += kwt(28);
    }
    if(self.voiceUrl.length > 0){
        H += kwt(46);
    }
    if(self.applyType == 1){
        H += kwt(66);
    } else {
        H += kwt(96);
    }
    return kwt(115 + 10 + 12) + H + self.tissueListStrH;
}

//-(CGFloat)pondNameH{
//    if(_pondNameH == 0){
//        _pondNameH = [DTKTool textWithtitle:[NSString stringWithFormat:@"%@ %@",self.pondTissue,self.pondName] andSize:CGSizeMake(kwt(351), 10000) andFout:kCFont(16)].height;
//        if(_pondNameH < kwt(16)){
//            _pondNameH = kwt(16);
//        }
//    }
//    return _pondNameH;
//}
- (CGFloat)JJFooterH{
//    if(self.button){
//        return 0;
//    }
    if(self.handoverProcessModel){
        if(self.handoverProcessModel.reason.length > 0){
            return kwt(158) + self.handoverProcessModel.reasonH;
        }
        return kwt(129 + 16);
    } else {
        return kwt(278 + 16);
    }
}

- (void)setVoiceUrl:(NSString *)voiceUrl{
    _voiceUrl = voiceUrl;
    if(voiceUrl.length < 0){
        return;
    }

    AVURLAsset* audioAsset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:voiceUrl] options: @{AVURLAssetPreferPreciseDurationAndTimingKey:@(YES)}];
    [audioAsset loadValuesAsynchronouslyForKeys:@[@"duration"] completionHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            AVKeyValueStatus status = [audioAsset statusOfValueForKey:@"duration" error:nil];
            if(status == AVKeyValueStatusLoaded){
                CMTime audioDuration = audioAsset.duration;
                float audioDurationSeconds = CMTimeGetSeconds(audioDuration);
                self.voiceDuration = [NSString stringWithFormat:@"%.0f\"",round(audioDurationSeconds)];
                if(self.openDurationBlock){
                    self.openDurationBlock(self.voiceDuration);
                }
            }
        });
    }];
    
}
@end
